package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import org.owasp.esapi.ESAPI;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.ApplicablePlatformEnum;
import com.frogs.system.util.FullGoodsStatusEnum;
import com.frogs.system.util.GoodsCheckStatusEnum;
import com.frogs.system.util.GoodsStatusEnum;
import com.frogs.system.util.PromotionApplicablePlatformEnum;
import com.frogs.system.util.ShoppingCartCreateTypeEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class UserShoppingCartAddRequest extends Request {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4767696574237942262L;

	/**
	 * 购物车id
	 */
    private int shoppingCartId = 0;

    private int userId = 0;

    private int applicablePlatformId = ApplicablePlatformEnum.WEB.getId();
    
    private int subApplicablePlatformId = PromotionApplicablePlatformEnum.NEW_MALL.getId();

    private int originalGoodsId = 0;

    private int goodsId = 0;
    
    private int skuId = 0;

    private String productCode;

    private int number = 0;

    private int numberUpperLimit = 0;

    private int numberLowerLimit = 0;

    private int createType = ShoppingCartCreateTypeEnum.CREATE_TYPE_MANUAL.getId();

    private int isChecked = GoodsCheckStatusEnum.CHECKED_NO.getId();

    private int goodsStatus = GoodsStatusEnum.NORMAL.getId();

    private String specialAttr;

    private int merchantId = 1;

    private int familyMemberId = 0;

    private String autoprompting;

    private String salesMode;

    private String remark;

    private String iconLabel;
    
    private String userTraceId ; 
    
    private String expandCode;
    
    private String subExpandCode;
    
    private Integer mealId;
    
    private double price;
    
    private Integer brandId;
    
    private String tags;
    
    private String catIds;
    
    private Integer isSeckill;
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		

		price = Double.parseDouble(requestInfo.getParameter(ApiUrlParamEnum.goodsPrice.getParamName(), "0.0"));
		if(price < 0) {
			throw new RequestIllegalException("error price:"+price);
		}
		brandId = requestInfo.getIntAttribute(ApiUrlParamEnum.goodsBrandId.getParamName(), 0);
		tags = requestInfo.getParameter(ApiUrlParamEnum.tags.getParamName());
		catIds = requestInfo.getParameter(ApiUrlParamEnum.goodsCatIds.getParamName());
		
		this.shoppingCartId = requestInfo.getIntParameter(ApiUrlParamEnum.shoppingCartId.getParamName(),0);
		if(shoppingCartId < 0 ){
			shoppingCartId = 0;
		}
		
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName());
		this.userTraceId = requestInfo.getParameter(ApiUrlParamEnum.userTraceId.getParamName(), "");
		
		if ( userId <1 && StringUtil.isEmpty(userTraceId)) {
			throw new RequestIllegalException("error userId:"+userId +" or userTraceId is null");
		}
		
		this.applicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.applicablePlatformId.getParamName() , ApplicablePlatformEnum.WEB.getId());
		this.originalGoodsId = requestInfo.getIntParameter(ApiUrlParamEnum.originalGoodsId.getParamName(), 0);
		this.goodsId = requestInfo.getIntParameter(ApiUrlParamEnum.goodsId.getParamName());
		this.mealId = requestInfo.getIntParameter(ApiUrlParamEnum.mealId.getParamName(), 0);
		if ( goodsId < 1 && mealId < 1) {
			throw new RequestIllegalException("error goodsId or mealId: " + goodsId + ","+mealId);
		}
		this.skuId = requestInfo.getIntParameter(ApiUrlParamEnum.skuId.getParamName());
		if(skuId < 1){
			throw new RequestIllegalException("error skuId:"+skuId);
		}
		
		this.productCode = requestInfo.getParameter(ApiUrlParamEnum.productCode.getParamName(),"-");
		
		this.number = requestInfo.getIntParameter(ApiUrlParamEnum.number.getParamName(),1);
		this.numberUpperLimit = requestInfo.getIntParameter(ApiUrlParamEnum.numberUpperLimit.getParamName(),2000);
		this.numberLowerLimit = requestInfo.getIntParameter(ApiUrlParamEnum.numberLowerLimit.getParamName(),1);
		this.createType = requestInfo.getIntParameter(ApiUrlParamEnum.createType.getParamName(),ShoppingCartCreateTypeEnum.CREATE_TYPE_MANUAL.getId() );
		this.isChecked = requestInfo.getIntParameter(ApiUrlParamEnum.isChecked.getParamName(),GoodsCheckStatusEnum.CHECKED_NO.getId());
		this.goodsStatus = requestInfo.getIntParameter(ApiUrlParamEnum.goodsStatus.getParamName(),GoodsStatusEnum.NORMAL.getId());
		
		this.specialAttr = requestInfo.getParameter(ApiUrlParamEnum.specialAttr.getParamName(), "-");
		this.merchantId = requestInfo.getIntParameter(ApiUrlParamEnum.merchantId.getParamName(),1 );
		this.familyMemberId = requestInfo.getIntParameter(ApiUrlParamEnum.familyMemberId.getParamName(), 0);
		this.autoprompting = requestInfo.getParameter(ApiUrlParamEnum.autoprompting.getParamName(), "-");
		this.salesMode = requestInfo.getParameter(ApiUrlParamEnum.salesMode.getParamName(),"-");
		this.remark = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.remark.getParamName(),"-"));
		this.iconLabel = requestInfo.getParameter(ApiUrlParamEnum.iconLabel.getParamName(), "-");
		this.expandCode = requestInfo.getParameter(ApiUrlParamEnum.expandCode.getParamName(), "0");
		this.subExpandCode = requestInfo.getParameter(ApiUrlParamEnum.subExpandCode.getParamName(), "0");
		this.subApplicablePlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.subApplicablePlatform.getParamName(), PromotionApplicablePlatformEnum.NEW_MALL.getId());
		this.isSeckill = requestInfo.getIntParameter(ApiUrlParamEnum.isSeckill.getParamName(), FullGoodsStatusEnum.GOODS_NOT_SECKILL.getId());
		
	}

	public int getShoppingCartId() {
		return shoppingCartId;
	}

	public void setShoppingCartId(int shoppingCartId) {
		this.shoppingCartId = shoppingCartId;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	public int getApplicablePlatformId() {
		return applicablePlatformId;
	}

	public void setApplicablePlatformId(int applicablePlatformId) {
		this.applicablePlatformId = applicablePlatformId;
	}

	public int getOriginalGoodsId() {
		return originalGoodsId;
	}

	public void setOriginalGoodsId(int originalGoodsId) {
		this.originalGoodsId = originalGoodsId;
	}

	public int getGoodsId() {
		return goodsId;
	}

	public void setGoodsId(int goodsId) {
		this.goodsId = goodsId;
	}

	public String getProductCode() {
		return productCode;
	}

	public void setProductCode(String productCode) {
		this.productCode = productCode;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getNumberUpperLimit() {
		return numberUpperLimit;
	}

	public void setNumberUpperLimit(int numberUpperLimit) {
		this.numberUpperLimit = numberUpperLimit;
	}

	public int getNumberLowerLimit() {
		return numberLowerLimit;
	}

	public void setNumberLowerLimit(int numberLowerLimit) {
		this.numberLowerLimit = numberLowerLimit;
	}

	public int getCreateType() {
		return createType;
	}

	public void setCreateType(int createType) {
		this.createType = createType;
	}

	public int getIsChecked() {
		return isChecked;
	}

	public void setIsChecked(int isChecked) {
		this.isChecked = isChecked;
	}

	public int getGoodsStatus() {
		return goodsStatus;
	}

	public void setGoodsStatus(int goodsStatus) {
		this.goodsStatus = goodsStatus;
	}

	public String getSpecialAttr() {
		return specialAttr;
	}

	public void setSpecialAttr(String specialAttr) {
		this.specialAttr = specialAttr;
	}

	public int getMerchantId() {
		return merchantId;
	}

	public void setMerchantId(int merchantId) {
		this.merchantId = merchantId;
	}

	public int getFamilyMemberId() {
		return familyMemberId;
	}

	public void setFamilyMemberId(int familyMemberId) {
		this.familyMemberId = familyMemberId;
	}

	public String getAutoprompting() {
		return autoprompting;
	}

	public void setAutoprompting(String autoprompting) {
		this.autoprompting = autoprompting;
	}

	public String getSalesMode() {
		return salesMode;
	}

	public void setSalesMode(String salesMode) {
		this.salesMode = salesMode;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getIconLabel() {
		return iconLabel;
	}

	public void setIconLabel(String iconLabel) {
		this.iconLabel = iconLabel;
	}

	public int getSkuId() {
		return skuId;
	}

	public void setSkuId(int skuId) {
		this.skuId = skuId;
	}

	public String getUserTraceId() {
		return userTraceId;
	}

	public void setUserTraceId(String userTraceId) {
		this.userTraceId = userTraceId;
	}

	public String getExpandCode() {
		return expandCode;
	}

	public void setExpandCode(String expandCode) {
		this.expandCode = expandCode;
	}

	public Integer getMealId() {
		return mealId;
	}

	public void setMealId(Integer mealId) {
		this.mealId = mealId;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public Integer getBrandId() {
		return brandId;
	}

	public void setBrandId(Integer brandId) {
		this.brandId = brandId;
	}

	public String getTags() {
		return tags;
	}

	public void setTags(String tags) {
		this.tags = tags;
	}

	public String getCatIds() {
		return catIds;
	}

	public void setCatIds(String catIds) {
		this.catIds = catIds;
	}

	public int getSubApplicablePlatformId() {
		return subApplicablePlatformId;
	}

	public void setSubApplicablePlatformId(int subApplicablePlatformId) {
		this.subApplicablePlatformId = subApplicablePlatformId;
	}

	public Integer getIsSeckill() {
		return isSeckill;
	}

	public void setIsSeckill(Integer isSeckill) {
		this.isSeckill = isSeckill;
	}

	public String getSubExpandCode() {
		return subExpandCode;
	}

	public void setSubExpandCode(String subExpandCode) {
		this.subExpandCode = subExpandCode;
	}
	
}
